package com.moxiao.yfjh.module.maker.dal.mysql.makerProductInfo;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.mybatis.core.mapper.BaseMapperX;
import com.moxiao.yfjh.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.moxiao.yfjh.module.maker.controller.admin.makerProductInfo.vo.MatchmakerProductInfoExportReqVO;
import com.moxiao.yfjh.module.maker.controller.admin.makerProductInfo.vo.MatchmakerProductInfoPageReqVO;
import com.moxiao.yfjh.module.maker.dal.dataobject.makerProductInfo.MatchmakerProductInfoDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 相亲红娘商品信息 Mapper
 *
 * @author mx
 */
@Mapper
public interface MatchmakerProductInfoMapper extends BaseMapperX<MatchmakerProductInfoDO> {

    default PageResult<MatchmakerProductInfoDO> selectPage(MatchmakerProductInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MatchmakerProductInfoDO>()
                .eqIfPresent(MatchmakerProductInfoDO::getNo, reqVO.getNo())
                .likeIfPresent(MatchmakerProductInfoDO::getName, reqVO.getName())
                .eqIfPresent(MatchmakerProductInfoDO::getSupplyPrice, reqVO.getSupplyPrice())
                .eqIfPresent(MatchmakerProductInfoDO::getMatchmakerCover, reqVO.getMatchmakerCover())
                .eqIfPresent(MatchmakerProductInfoDO::getProductIntroduct, reqVO.getProductIntroduct())
                .eqIfPresent(MatchmakerProductInfoDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MatchmakerProductInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MatchmakerProductInfoDO::getId));
    }

    default List<MatchmakerProductInfoDO> selectList(MatchmakerProductInfoExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MatchmakerProductInfoDO>()
                .eqIfPresent(MatchmakerProductInfoDO::getNo, reqVO.getNo())
                .likeIfPresent(MatchmakerProductInfoDO::getName, reqVO.getName())
                .eqIfPresent(MatchmakerProductInfoDO::getSupplyPrice, reqVO.getSupplyPrice())
                .eqIfPresent(MatchmakerProductInfoDO::getMatchmakerCover, reqVO.getMatchmakerCover())
                .eqIfPresent(MatchmakerProductInfoDO::getProductIntroduct, reqVO.getProductIntroduct())
                .eqIfPresent(MatchmakerProductInfoDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MatchmakerProductInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MatchmakerProductInfoDO::getId));
    }

    /**
     * 红娘商品购买销量
     *
     * @param productId
     * @return
     */
    @Select("select IFNULL(COUNT(order_id),0)  num from blind_trade_order where order_type = 4 and pay_status = 1 and order_id = #{productId}")
    Integer getMakerSalesVolume(@Param("productId") Long productId);
}
